<include file="./../Application/Cms/View/default/header.html"/>
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="__STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>


<script type="text/javascript">
    var ue = UE.getEditor('content');
</script>
<div class="main">
    <include file="./../Application/Cms/View/default/left.html"/>
    <div class="main_right">
        <div class="right_1">
            <!--右边导航s-->
            <div class="right_1_1">
                <div class="nav_left">
                    <a href="<{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/lists',['type' => $type],'html')}>" class="nav_current">返回列表</a>
                </div>
            </div>
            <div class="right_1_2">
                <form action="<{$url_current}>" method="post">
                    <table cellspacing="0" cellpadding="0" class="main_table">
                        <tr>
                            <th><i class="require-red">*</i>分类：</th>
                            <td>
                                <select name="cid">
                                    <option value="">--全部--</option>
                                    <foreach name="category" item="list">
                                        <if condition="$list[_child]">
                                            <optgroup label="<{$list.title}>">
                                                <foreach name="list[_child]" item="i">
                                                    <option value="<{$i.id}>"
                                                    <if condition="$i[id] eq $data[cid]">selected="selected"</if>
                                                    ><{$i.title}></option>
                                                </foreach>
                                            </optgroup>
                                            <else/>
                                            <option value="<{$list.id}>"
                                            <if condition="$list[id] eq $data[cid]">selected="selected"</if>
                                            ><{$list.title}></option>
                                        </if>
                                    </foreach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th><i class="require-red">*</i>文章标题：</th>
                            <td><input type="text" name="title" value="<{$data.title|htmlspecialchars_decode}>"
                                       class="txt_basic validate" size="80"/></td>
                        </tr>

                        <tr>
                            <th><i class="require-red">*</i>主图：</th>
                            <td>
                                <input id="uploadify" type="file"/>
                                <div id="image"></div>
                            </td>
                            <input type="hidden" name="img" value="<{$data.img}>"/>
                        </tr>
                        <script type="text/javascript">
                            $(function () {
                                $('#uploadify').uploadify({
                                    'auto': true,
                                    'buttonText': '选择文件',
                                    'multi': false,
                                    'formData': {
                                        'timestamp': '<php> echo time();</php>',
                                        'img_code': '<php> echo md5('unique_salt' . time());</php>',
                                        'folder': '<{$Think.CONTROLLER_NAME}>'
                                    },
                                    'swf': '__STATIC__/uploadify/uploadify.swf',
                                    'uploader': '/Tool/main/upload.html',
                                    'onUploadSuccess': funComplete,
                                });
                            });

                            function funComplete(file, data, response) {
                                if (response == 0) {
                                    alert('图片' + fileObj.name + '操作失败');
                                    return false;
                                } else {
                                    res = JSON.parse(data);
                                    if(res.code == 'ok'){
                                        var add = "<img src='" + res.data.img + "' style='margin-left:15px;margin-top:15px;height:100px;'/></img>";
                                        $('#image').html(add);
                                        $("input[name='img']").val(data)
                                        return true;
                                    }else{
                                        alert(res.error)
                                        return false
                                    }

                                }
                            }

                        </script>
                        <if condition="$data[img]">
                            <tr>
                                <th><i class="require-red"></i></th>
                                <td><img src="<{$data.img}>" height="100"></td>
                            </tr>
                        </if>

                        <if condition="$type eq 'case'">
                            <tr>
                                <input type="hidden" name="images" value="<php>echo implode(',', $data['images']);</php>"/>
                                <th><i class="require-red"></i>更多图片：</th>
                                <td><input name="more_imgs" id="more_imgs" class="txt_basic" type="file"
                                           multiple="true"/>
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <div id="image_2">
                                        <if condition="$data[images]">
                                            <foreach name="data.images" item="img">
                                                <div>
                                                    <img src='<{$img.img}>' height="100"/>
                                                    <span class="pic_del"  title="删除" alt="删除"></span>
                                                </div>
                                            </foreach>
                                        </if>
                                    </div>
                                </td>
                            </tr>
                            <script type="text/javascript">
                                $(function () {
                                    $('#more_imgs').uploadify({
                                        'auto': true,
                                        'buttonText': '选择文件',
                                        'formData': {
                                            'timestamp': '<php> echo time();</php>',
                                            'img_code': '<php> echo md5('unique_salt' . time());</php>',
                                            'folder': '<{$Think.CONTROLLER_NAME}>'

                                        },
                                        'swf': '__STATIC__/uploadify/uploadify.swf',
                                        'uploader': '/Tool/main/upload.html',
                                        'onUploadSuccess': funComplete_1,
                                    });
                                });

                                function funComplete_1(file, data, response) {
                                    if (response == 0) {
                                        alert('图片' + fileObj.name + '操作失败');
                                        return false;
                                    } else {
                                        res = JSON.parse(data);
                                        if(res.code == 'ok'){
                                            var str = $('#image_2').html();
                                            var add = "<div><img src='" + res.data.img + "'/></img><span class='pic_del' title='删除'></span></div>";
                                            str += add;
                                            $('#image_2').html(str);
                                            //追加结果到原数据
                                            var images_orign = $("input[name='images']").val()

                                            var images_arr = images_orign.split(',')
                                            images_arr.push(res.data.img)
                                            images_arr.join(',')

                                            $("input[name='images']").val(images_arr)
                                        }else{
                                            alert(res.error)
                                            return false
                                        }

                                    }
                                }
                            </script>
                        </if>

                        <tr>
                            <th><i class="require-red"></i>简介：</th>
                            <td>
                                <p class="th-header">*简介内容为空时，默认截取文章内容前100个字符
                                </p>
                                <textarea rows="5" cols="90" name="intro" class=""><{$data.intro|htmlspecialchars_decode}></textarea>
                            </td>
                        </tr>
                        <tr>
                            <th><i class="require-red">*</i>内容：</th>
                            <td>
                                <script id="content" name="content" type="text/plain" style="width:100%;height:300px;">
                                    <{$data.content|htmlspecialchars_decode}>
                                </script>
                            </td>
                        </tr>

                        <tr>
                            <th></th>
                            <td><input type="button" id="form-submit" value="保存" class="btn_submit"/></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<include file="./../Application/Cms/View/default/footer.html"/>